#ifndef _Ape__DateTime_h
#define _Ape__DateTime_h

#include <Ape/Object.h>
#include <Ape/UInt.h>
#include <Ape/Int.h>

#if defined(APE_USES_TIME_T)
#include <time.h>
#endif


namespace Ape {
	class String;
	class UInt;
	
	class DateDiff : public Object {
		TYPE_NAME ("Ape::DateDiff")
	private:
		Int m_Sec;
		Int m_MiSec;
		bool m_Negative;
	public:
		DateDiff (const Int& seconds, const Int& microSeconds, bool negative = false);
		DateDiff (const DateDiff& other);
		virtual ~DateDiff();
		
		const Int& get_Sec() const;
		const Int& get_MiSec() const;
		bool get_Negative() const;
		
		void set_Sec (const Int& v);
		void set_MiSec (const Int& v);
		void set_Negative (bool b);
		
		virtual const String ToString() const;
	};
	
	
	class DateTime : public Object {
		TYPE_NAME ("Ape::DateTime")
	private:
		UInt m_Year;
		UInt m_Month;
		UInt m_MDay;
		
		UInt m_Hour;
		UInt m_Min;
		UInt m_Sec;
		UInt m_MiSec;
		
#if defined(APE_USES_TIME_T)
		mutable bool m_TimeInfoIsSet;
		mutable struct tm m_TimeInfo;
		mutable time_t m_UnixTime;
#endif
		
		//void UpdateTime();
		
		const char** getWDays() const;
		
	public:
		DateTime();
		DateTime (const DateTime& other);
		virtual ~DateTime();
		
		UInt get_Year() const;
		UInt get_Month() const;
		UInt get_MDay() const;
		UInt get_Hour() const;
		UInt get_Min() const;
		UInt get_Sec() const;
		UInt get_MiSec() const;
		UInt get_WDay() const;
		
		void set_Year (UInt v);
		void set_Month (UInt v);
		void set_MDay (UInt v);
		void set_Hour (UInt v);
		void set_Min (UInt v);
		void set_Sec (UInt v);
		void set_MiSec (UInt v);
		
		bool isValid() const;
		
		virtual const String ToString() const;
		virtual void _Dump (bool verbose = false) const;
		
		static DateTime Current();
		static DateTime Parse (const String& sTime);
		
		time_t ToUnixTime() const;
	};
	
	bool operator == (const DateTime& dt1, const DateTime& dt2);
	bool operator != (const DateTime& dt1, const DateTime& dt2);
	bool operator < (const DateTime& dt1, const DateTime& dt2);
	bool operator > (const DateTime& dt1, const DateTime& dt2);
	bool operator <= (const DateTime& dt1, const DateTime& dt2);
	bool operator >= (const DateTime& dt1, const DateTime& dt2);
	const DateDiff operator - (const DateTime& dt1, const DateTime& dt2);
	
	bool operator == (const DateDiff& dd1, const DateDiff& dd2);
	bool operator != (const DateDiff& dd1, const DateDiff& dd2);
	
	const DateDiff operator - (const DateDiff& dd1, const DateDiff& dd2);
	const DateDiff operator + (const DateDiff& dd1, const DateDiff& dd2);
	
	
}

#endif // _Ape__DateTime_h
